<template>
  <div class="home">
    <div class="title">易洁家政</div>
    <!--轮播图 -->
    <van-swipe class="swipe" :autoplay="3000">
      <van-swipe-item v-for="(image, index) in carousel" :key="index">
        <img width="100%" v-lazy="image.url" />
      </van-swipe-item>
    </van-swipe>
    <!-- 导航栏-->
    <van-grid class="my-grid" :column-num="6">
      <van-grid-item
        v-for="(value, index) in productcategory"
        :key="index"
        :icon="value.icon"
        :text="value.name"
        @click="toHandler(index, value.id)"
      />
    </van-grid>

    <!-- 商品卡片 -->
    <div class="card">
      <van-card
        v-for="(value, index) in product"
        :key="index"
        :desc="value.description"
        :title="value.name"
        :thumb="value.photo"
      />
    </div>
  </div>
</template>
<script>
import { get } from "@/http/axios.js";
import { mapMutations } from 'vuex';
export default {
  data() {
    return {
      status: "",
      carousel: [],
      productcategory: [],
      product: [],
    };
  },
  methods: {
    ...mapMutations("shopcart", ["clearShopcart"]),
    //  轮播图
    findAllCarousel() {
      get("/carousel/query", this.status).then((res) => {
        //   console.log(res.data);
        if (res.data.status == 200) {
          this.carousel = res.data.data;
          this.carousel = this.carousel.filter((carousel) => {
            return carousel.status === "正常";
          });
        } else {
          this.$message({
            type: "error",
            message: this.message,
          });
        }
      });
    },
    //导航栏
    findAllProductCategory() {
      let data = {
        page: 1,
        pageSize: 10,
      };
      get("/productCategory/pageQuery", data).then((res) => {
        // console.log(res.data);
        if (res.data.status == 200) {
          this.productcategory = res.data.data.list;
        } else {
          this.$message({
            type: "error",
            message: this.message,
          });
        }
      });
    },
    // 产品展示
    findAllProduct() {
      let data = {
        page: 1,
        pageSize: 10,
      };
      get("/product/pageQuery", data).then((res) => {
        // console.log(res.data.data);
        if (res.data.status == 200) {
          this.product = res.data.data.list;
          // console.log(this.product);
        } else {
          this.$message({
            type: "error",
            message: this.message,
          });
        }
      });
    },
    // 调转产品页面
    toHandler(index, id) {
      // alert(888)
      this.clearShopcart()
      this.$router.push({
        path: "/manager/productlist",
        query: { activeKey: index, categoryId: id },
      });
    },
  },
  created() {
    this.findAllCarousel();
    this.findAllProductCategory();
    this.findAllProduct();
  },
};
</script>
<style scoped>
.home .title {
  height: 130px;
  background-image: linear-gradient(90deg, #7579ff, #bf73ff);
  color: #fff;
  border-bottom-left-radius: 28px;
  border-bottom-right-radius: 28px;
  font-size: 29px;
  padding-top: 5px;
}
.home .swipe {
  height: 160px;
  width: 90%;
  position: absolute;
  top: 136px;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px 0 #aaa;
  border-radius: 8px;
}
.home .my-grid {
  margin-top: 100px;
  cursor: pointer;
}
.home .card {
  /* margin-top: 2em; */
  padding-bottom: 50px;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}
.home .card .van-card {
  margin: 13px;
  box-sizing: border-box;
  box-shadow: 0 0 5px 0 #eadaff;
  background-color: #fff;
  border-radius: 5px;
  height: 160px;
  width: 180px;
  text-align: center;
}
.van-card__thumb {
  width: 130px;
  height: 80px;
  left: 10px;
}

.home .card .van-card .van-card__title {
  height: 30px;
  /* font-family:webfont; */
  font-weight: 700;
  font-size:17px;
  color: #333;
  float: left;
  margin-top: 95px;
  margin-left: -100px;
}
.home .card .van-card .van-card__desc {
  /* font-family:webfont; */
  font-weight: 500;
  font-size:16px;
  color: #333;
  float: left;
  margin-top: 120px;
  margin-left: -98px;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
</style>